package kr.hyunist.androidcomplete01saeildamil.ch19;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.content.*;
import android.content.DialogInterface.OnClickListener;
import android.os.*;
import android.view.*;
import android.widget.*;

public class UploadEx02 extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.uploadex);
	}
	
	public void mOnClick(View v){
		new AlertDialog.Builder(this)
		.setTitle("질문")
		.setMessage("업로드하시겠습니까?")
		.setPositiveButton("예", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				mHandler.sendEmptyMessageDelayed(0, 10);
			}
			
		})
		.setNegativeButton("아니오", null)
		.show();
	}
	
	Handler mHandler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			if(msg.what == 0){
				doUpload();
			}
		}
		
	};

	protected void doUpload() {
		for(int i = 0; i < 20; i++){
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		Toast.makeText(this, "업로드 완료", 0).show();		
	}
}
